package com.vonchange.utils.springmvc;

import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

public class SpringContextUtils {
	   static WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
        @SuppressWarnings("unchecked")
		public  static  <T>T  getBean(String name){
        	String namex=name;
        	if(!name.endsWith("Impl")){
        		namex=name+"Impl";
        	}
             if(wac.containsBean(namex)){
            	  return  (T)wac.getBean(namex);
             }
            if(wac.containsBean(name)){
            	return (T)wac.getBean(name);  	
            }
			return null;
        }
}
